<%page args="p, table, popts=None" />

<%include file="header.html" />
<%namespace file="utils.html" import="*" />
<script type="text/javascript">

function addoption()	{
	
	$("#polloptions").append("<form id=\"newoption\"><label for=\"ANSWER\">Answer</label>"+
	"<input type=\"text\" name=\"ANSWER\" maxlength=128 />" + 
	"<a href=\"javascript:saveanswer()\">Save Answer</a></form><br />");
}

function saveanswer()	{
	$("#polloptions").load("/polls/saveanswer", 
		{
			"answer":document.forms[1].elements[0].value,
			"pollid":${p.POLLID}
		}
	);
	$(".polls").load("/polls/currentpoll");
}

function deleteoption(opt) {
	$("#polloptions").load("/polls/deleteoption", {"optionid":opt, "pollid": ${p.POLLID}});
	$(".polls").load("/polls/currentpoll");
}

</script>


<h2>Edit Poll
(
<a href="/polls/deletepoll?pollid=${p.POLLID}">Delete</a> 
-
<a href="/polls">View All</a>
)
</h2>
${createform(p,table,"/polls/savepoll")}
<div id="polloptions">
Loading Poll Options
</div>
<script>
$("#polloptions").load("/polls/displaypolloptions", {"pollid": ${p.POLLID}});
</script>
<a href="javascript:addoption()">Add Option</a>
<%include file="footer.html" />
